package com.hh.erp.util.page;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class PageInfo implements Serializable {

    private static Integer initPageNum = 1;
    private static Integer initPageSize = 10;

    private Integer pageNum; // 页数
    private Integer pageSize; // 页大小

    private List<?> data; // 数据
    private Long total; // 总记录数

    private Integer pageIndex; //起始行，主要是给数据库使用

    public Integer getPageIndex() {
        return (this.pageNum-1) * this.pageSize;
    }


    public void setPageData(List<?> data,Long total) {
        this.data = data;
        this.total = total;
    }

    public static PageInfo start(Integer pageNum,Integer pageSize) {

        if(pageNum == null) {
            pageNum = initPageNum;
        }
        if(pageSize == null) {
            pageSize = initPageSize;
        }

        PageInfo page = new PageInfo();
        page.pageNum = pageNum;
        page.pageSize = pageSize;
        return page;
    }
}
